{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='The image depicts a picturesque natural landscape featuring a wooden boardwalk that stretches through a grassy field. The boardwalk is surrounded by lush green grass, small shrubs, and trees in the background. The sky is vibrant blue with a scattering of soft white clouds, suggesting a clear and pleasant weather condition. The overall scene is serene and inviting, emanating a sense of tranquility and connection with nature.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))\n"
     ]
    }
   ],
   "source": [
    "from openai import OpenAI\n",
    "client = OpenAI(\n",
    "    base_url='https://xiaoai.plus/v1',\n",
    "    # sk-xxx替换为自己的key\n",
    "    api_key='sk-lYp1RcVMaX4uHjcnLasZ75DPNrpXSxx0dJTDxBCKZ1TJKHPi'\n",
    ")\n",
    "response = client.chat.completions.create(\n",
    "    model=\"gpt-4o\",\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\"type\": \"text\", \"text\": \"What's in this image?\"},\n",
    "                {\n",
    "                    \"type\": \"image_url\",\n",
    "                    \"image_url\": {\n",
    "                        \"url\": \"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg\",\n",
    "                    }\n",
    "                },\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    "    max_tokens=300,\n",
    ")\n",
    "print(response.choices[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://xiaoai.plus/v1\n",
      "Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='The image shows a wooden boardwalk pathway through a vast, open field of tall grass, under a beautiful blue sky with some scattered clouds. The scene is bright with the sunlight enhancing the vividness of the green grass. In the distance, there are trees and shrubbery, adding to the serene and natural setting. The boardwalk guides the eye towards the horizon, contributing to the tranquil and inviting atmosphere of the image.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}})\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('/home/tom/my_learn/my_danwen/rag')\n",
    "from ast import main\n",
    "from config import RagConfig\n",
    "from openai import OpenAI\n",
    "\n",
    "from utils import get_b64_image_from_path\n",
    "from llms import vllm\n",
    "\n",
    "client = vllm()\n",
    "response = client.chat.completions.create(\n",
    "    model=\"gpt-4o\",\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\"type\": \"text\", \"text\": \"What's in this image?\"},\n",
    "                {\n",
    "                    \"type\": \"image_url\",\n",
    "                    \"image_url\": {\n",
    "                        \"url\": \"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg\",\n",
    "                    }\n",
    "                },\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    "    max_tokens=300,\n",
    ")\n",
    "print(response.choices[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('/home/tom/my_learn/my_danwen/rag')\n",
    "from ast import main\n",
    "from config import RagConfig\n",
    "from openai import OpenAI\n",
    "\n",
    "from utils import get_b64_image_from_path\n",
    "from llms import vllm\n",
    "\n",
    "client = vllm()\n",
    "response = client.chat.completions.create(\n",
    "    model=\"gpt-4o\",\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\"type\": \"text\", \"text\": \"What's in this image?\"},\n",
    "                {\n",
    "                    \"type\": \"image_url\",\n",
    "                    \"image_url\": {\n",
    "                        \"url\": \"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg\",\n",
    "                    }\n",
    "                },\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    "    max_tokens=300,\n",
    ")\n",
    "print(response.choices[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://xiaoai.plus/v1\n",
      "Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='图片中是一只躺在灰色和白色被窝里的橙白相间的猫。猫咪的头露出在被子外，显得十分舒适和放松。', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}})\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('/home/tom/my_learn/my_danwen/rag')\n",
    "from ast import main\n",
    "from config import RagConfig\n",
    "from openai import OpenAI\n",
    "\n",
    "from utils import get_b64_image_from_path\n",
    "from llms import vllm\n",
    "\n",
    "file_path='/home/tom/my_learn/my_danwen/0_playgrounds/0_test_data/南瓜.png'\n",
    "image_b64 = get_b64_image_from_path(file_path)\n",
    "\n",
    "client = vllm()\n",
    "response = client.chat.completions.create(\n",
    "    model=\"gpt-4o\",\n",
    "    messages = [\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\":\n",
    "                [\n",
    "                    {\n",
    "                        \"type\": \"text\",\n",
    "                        \"text\": '简单描述一下图片'\n",
    "                    },\n",
    "                    {\n",
    "                        \"type\": \"image_url\",\n",
    "                        \"image_url\":{\"url\": f\"data:image/png;base64,{image_b64}\"}\n",
    "                        }\n",
    "                ]\n",
    "            }\n",
    "    ],\n",
    "    max_tokens=300,\n",
    ")\n",
    "print(response.choices[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "danwen",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
